package cs6238.common.message.command;

import java.nio.ByteBuffer;

import cs6238.common.ByteArray;
import cs6238.common.message.MessageId;

public class PutFileCommand extends Command {

	private String _clientFilename;
	
	@Override
	public byte[] serialize() {
		byte[] clientFilenameBytes = ByteArray.writeString(_clientFilename);
		ByteBuffer bb = ByteBuffer.allocate(4 + clientFilenameBytes.length);
		bb.putInt(MessageId.PUT_FILE_COMMAND.ordinal());
		bb.put(clientFilenameBytes);
		return bb.array();
	}

	@Override
	public void deserialize(byte[] buffer) {
		ByteBuffer bb = ByteBuffer.wrap(buffer);
		bb.getInt();
		_clientFilename = ByteArray.readString(bb);
	}

	public void setClientFilename(String filename) {
		_clientFilename = filename;
	}
	
	public String getClientFilename(){
		return _clientFilename;
	}

}
